package com.itheima.mq;

import org.springframework.amqp.rabbit.annotation.RabbitListener;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.MailException;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Component;

@Component
public class Email {
    @Autowired
    private JavaMailSenderImpl javaMailSender;
    @Value("${spring.mail.username}")
    String name;
    @RabbitListener(queues = "hello")
    public void send(String email){
        try {
            SimpleMailMessage message = new SimpleMailMessage();
            message.setSubject("查水表");
            message.setText("除了一针一线剩下的全搬走");
            message.setTo(email);
            message.setFrom(name);
            javaMailSender.send(message);
        } catch (MailException e) {
            e.printStackTrace();
        }
    }
}
